// 组件允许单个组件打包，因此默认引入公共基础样式

@import "../../base.less";

@import "./_var.less";

@import "./_mixin.less";

@import "../../mixins/_layout.less";

a.@{prefix}-menu__item {
  text-decoration: none;
  color: unset;

  &:hover,
  &:active {
    color: inherit;
  }
}

// head-menu
.@{prefix}-head-menu {
  position: relative;
  width: 100%;
  background-color: @menu-theme-light;

  &__inner {
    display: flex;
    height: 64px;

    li + li {
      margin-left: 4px;
    }

    .@{prefix}-menu {
      &:first-child {
        margin-left: 24px;
      }
    }
  }

  .@{prefix}-menu__logo:not(:empty) {
    height: 100%;
    font-size: 0;
    margin-right: 32px;
  }

  .@{prefix}-menu {
    flex: 1;
    display: flex;
    align-items: center;
  }

  .@{prefix}-menu__operations {
    &:not(:empty) {
      position: relative;
      display: flex;
      align-items: center;
      height: 64px;
      line-height: 64px;
      text-align: right;
      margin-right: 8px;
      overflow: hidden;
    }

    &-icon {
      width: 40px;
      height: 40px;
      padding: 8px;
      line-height: 40px;
    }
  }

  .@{prefix}-submenu {

    > .@{prefix}-menu__item {
      overflow: unset;

      &::before {
        content: "";
        display: block;
        position: absolute;
        bottom: -20px;
        left: 0;
        right: 0;
        height: 20px;
      }
    }
  }

  .@{prefix}-menu__item {
    min-width: @head-menu-item-width;
    height: @head-menu-item-height;
    line-height: @head-menu-item-height;
    justify-content: center;
    transition: all @anim-duration-slow cubic-bezier(.645, .045, .355, 1);
  }

  &__submenu {
    border-top: 1px solid @head-menu-submenu-border-color;

    // menu 双层导航使用了 Tabs 实现，需要 tab 样式保持跟 menu theme 一致，不跟随整体亮色/暗色模式切换
    .@{prefix}-tabs {
      background: #fff;

      &__bar {
        background-color: @submenu-dark-item-active-color;
      }

      &__nav-item {
        color: @font-gray-2;

        &-wrapper {
          --ripple-color: @menu-item-animation-bg--light;
        }

        &:not(.@{prefix}-is-disabled):not(.@{prefix}-is-active):hover {

          .@{prefix}-tabs__nav-item-wrapper {
            background-color: @menu-light-hover-bg;
          }
        }

        &.@{prefix}-is-active {
          color: @submenu-item-active-color;
        }

        &.@{prefix}-is-disabled {
          color: @menu-item-disabled-color;
        }

        --ripple-color: @menu-item-animation-bg--light;
      }
    }
  }

  .@{prefix}-menu__popup {
    top: 60px;
    min-width: 100%;
    box-sizing: content-box;
    transform-origin: center top;

    .@{prefix}-menu__item {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      white-space: nowrap;
      padding-left: 16px;
      padding-right: 16px;
      min-width: 100%;
      margin-left: 0;
      color: @head-menu-popup-item-color;
    }

    li + li {
      margin-top: 4px;
      margin-left: 0;
    }
  }

  .@{prefix}-submenu-icon { // to remove
    margin-left: 8px;
  }

  .@{prefix}-fake-arrow {
    margin-left: 8px;
  }

  // 多层情况
  .@{prefix}-menu__popup-inner {

    .@{prefix}-menu__popup {
      top: -8px;
      left: calc(100% + 16px);
      transform-origin: left top;
    }

    .@{prefix}-menu__item {
      text-align: left;
      padding: 0 16px;
      justify-content: space-between;
    }

    .@{prefix}-submenu-icon {
      transform: rotate(270deg);
    }
  }
}

// default-menu
.@{prefix}-default-menu {
  position: relative;
  width: @default-menu-width;
  display: inline-block;
  background: @menu-theme-light;
  transition: width @anim-duration-slow cubic-bezier(.645, .045, .355, 1);
  white-space: nowrap;

  &.@{prefix}-menu--dark {
    background: @menu-theme-dark;

    .@{prefix}-menu__logo:not(:empty) {
      border-bottom-color: @menu-border-color--dark;
    }

    .@{prefix}-menu__operations:not(:empty) {
      border-top-color: @menu-border-color--dark;
    }

    .@{prefix}-menu__item {

      &:hover:not(.@{prefix}-is-active):not(.@{prefix}-is-disabled) {
        background-color: @menu-border-color--dark;
      }

      &.@{prefix}-is-active:not(.@{prefix}-is-opened) {
        background-color: @default-menu-active-color;
      }

      &.@{prefix}-is-opened {
        color: @menu-theme-light;
      }

      &.@{prefix}-is-opened.@{prefix}-is-active {
        background-color: transparent;
      }
    }

    .@{prefix}-menu__popup {
      background: @menu-theme-dark;

      .@{prefix}-menu__item {

        &.@{prefix}-is-active {
          background-color: @default-menu-active-color;
        }
      }
    }

    .@{prefix}-menu__popup {
      background: @menu-theme-dark;
    }

    .@{prefix}-menu-group__title {
      color: @menu-menu-group-title-color--dark;
    }

    &.@{prefix}-is-collapsed .@{prefix}-menu-group__title:after {
      background-color: @menu-group-title-bg--collapse--dark;
    }
  }

  &.@{prefix}-is-collapsed {
    width: @default-menu-collapse-width;

    .@{prefix}-menu {

      .@{prefix}-menu__item {
        padding: 0 14px;
      }
    }

    .@{prefix}-fake-arrow {
      display: none;
    }

    .@{prefix}-menu__item {
      text-overflow: initial;

      &.@{prefix}-is-active.@{prefix}-is-opened {
        color: @menu-theme-light;
        background-color: @default-menu-active-color;

        .@{prefix}-icon {
          color: @menu-theme-light;
        }
      }

      &.@{prefix}-menu__item--plain::after {
        content: "1";
      }

      span {
        display: none;
      }

      .@{prefix}-icon {
        margin-right: initial;
      }
    }

    .@{prefix}-menu__popup {

      .@{prefix}-menu__item {
        padding-left: @popup-item-padding-left;
        justify-content: flex-start;

        span {
          display: inline;
        }

        &.@{prefix}-menu__item--plain::after {
          content: "";
        }
      }

      .@{prefix}-fake-arrow {
        display: block;
      }
    }

    .@{prefix}-submenu {
      &-icon {
        display: none;
      }

      .@{prefix}-menu__popup {

        .@{prefix}-submenu-icon {
          display: initial;
        }
      }

      > .@{prefix}-menu__item {
        min-width: initial;

        &::after {
          content: "";
          display: block;
          position: absolute;
          right: -20px;
          top: 0;
          bottom: 0;
          width: 20px;
        }
      }
    }

    .@{prefix}-menu-group__title {
      padding: 0;
      font-size: 0;

      &::after {
        content: "";
        display: block;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        height: 1px;
        width: 20px;
        background: @menu-group-title-bg--collapse;
      }
    }

    .@{prefix}-menu__operations {
      text-align: center;

      &-icon {
        display: block;
      }
    }
  }

  &__inner {
    display: flex;
    flex-direction: column;
    height: 100%;

    .@{prefix}-menu__logo:not(:empty) {
      width: 100%;
      height: 64px;
      border-bottom: 1px solid @menu-border-color;
    }

    .@{prefix}-menu {
      padding: 16px 8px;
      position: relative;
      // overflow-y: auto;
      flex: 1;

      &--scroll {
        overflow-y: auto;
      }
    }

    .@{prefix}-menu-group {
      &__title {
        position: relative;
        padding: 20px 16px 8px;
        height: 48px;
        line-height: 20px;
        color: @menu-menu-group-title-color;
        font-size: @menu-extra-fontsize;
      }
    }
  }

  .@{prefix}-submenu {
    margin-bottom: 4px;
    position: relative;
  }

  .@{prefix}-menu__operations {
    &:not(:empty) {
      width: 100%;
      position: relative;
      padding: 8px 16px;
      top: 0;
      left: 0;
      text-align: left;
      border-top: solid 1px @menu-border-color;
    }

    &-icon {
      width: 32px;
      height: 32px;
      padding: 8px;
      cursor: pointer;
      color: @menu-operations-color;
    }
  }

  .@{prefix}-menu__item {

    &.@{prefix}-is-opened {
      margin: 4px 0;
      color: @menu-light-active-color;
      background-color: unset;

      .@{prefix}-icon {
        color: @menu-light-active-color;
      }
    }
  }

  .@{prefix}-menu__dropdown {
    // display: none;
    // position: static;
    overflow: hidden;
    transition: max-height @anim-duration-slow cubic-bezier(.645, .045, .355, 1);
    // height: 0;

    .@{prefix}-menu__item {
      padding-left: 64px;
    }

    &--show {
      display: block;
    }
  }

  .@{prefix}-menu__sub {
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height @anim-duration-base @anim-time-fn-easing;

    &.@{prefix}-is-opened {
      max-height: 1000px;
    }

    .@{prefix}-menu__item {
      padding-left: var(--padding-left, 32px);
    }
  }

  .@{prefix}-menu__popup {
    top: 0;
    left: calc(100% + 16px);
  }

  .@{prefix}-menu__item {
    position: relative;
    margin: 4px 0;
    padding: 0 10px 0 16px;
    height: @default-menu-item-height;
    line-height: @default-menu-item-height;
    border-bottom: 0;
    text-align: left;
    border-radius: @border-radius;
    transition:
      background-color @anim-duration-slow @anim-time-fn-easing,
      padding @anim-duration-slow @anim-time-fn-easing;

    &:first-child {
      margin-top: 0;
    }

    &:last-child {
      margin-bottom: 0;
    }

    .@{prefix}-icon {
      width: 20px;
      height: 20px;
    }

    .@{prefix}-fake-arrow {
      margin-left: auto;
    }

    &.@{prefix}-is-active:not(.@{prefix}-is-opened) {
      color: @menu-theme-light;
      background-color: @default-menu-active-color;

      .@{prefix}-icon {
        color: @menu-theme-light;
      }
    }

    &:hover:not(.@{prefix}-is-active):not(.@{prefix}-is-disabled) {
      background: @menu-light-active-bg;

      & + .@{prefix}-menu__item {
        margin-top: 4px;
      }
    }
  }
}

// menu
.@{prefix}-menu {
  color: @menu-theme-light;
  font-size: @menu-fontsize;
  .list-style-none();

  &__logo {
    &:not(:empty) {
      display: flex;
      align-items: center;
    }
  }

  .@{prefix}-submenu {
    position: relative;

    &.@{prefix}-is-active {

      > .@{prefix}-menu__item {
        color: @menu-theme-dark;

        .@{prefix}-icon {
          color: @menu-theme-dark;
        }
      }
    }

    .@{prefix}-submenu-icon {
      width: 16px;
      height: 16px;
    }

    &.@{prefix}-is-opened {

      & .@{prefix}-submenu-icon {
        transform: scaleY(-1);
      }
    }
  }

  &__item {
    position: relative;
    display: flex;
    align-items: center;
    height: 64px;
    line-height: 64px;
    text-align: center;
    color: @menu-item-color--light;
    cursor: pointer;
    // overflow: hidden;
    text-overflow: ellipsis;
    border-radius: @border-radius;

    ::selection {
      background: transparent;
    }

    a {
      color: unset;
      text-decoration: none;

      &.@{prefix}-menu__item-link {
        color: unset;
      }
    }

    &.@{prefix}-is-active {
      color: @menu-item-active-color--light;
      background-color: @menu-item-active-bg--light;
    }

    &.@{prefix}-is-opened {
      font-weight: 500;
      color: @menu-item-active-color--light;
    }

    &:hover:not(.@{prefix}-is-active):not(.@{prefix}-is-opened):not(.@{prefix}-is-disabled) {
      background-color: @menu-item-hover-bg--light;
    }

    &.@{prefix}-is-disabled {
      color: @menu-item-disabled-color;
      cursor: not-allowed;
    }

    --ripple-color: @menu-item-animation-bg--light;
  }

  &__content {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .@{prefix}-icon + &__content {
    margin-left: 8px;
  }

  &--dark {

    &.@{prefix}-head-menu {
      background-color: @head-menu-bg--dark;

      .@{prefix}-menu__popup {
        background-color: @head-menu-bg--dark;
      }
    }

    .@{prefix}-menu__item {
      color: @menu-item-color--dark;

      &.@{prefix}-is-active {
        color: @menu-item-active-color--dark;
        background-color: @menu-item-active-bg--dark;
      }

      &.@{prefix}-is-opened {
        color: @menu-item-active-color--dark;

        .@{prefix}-icon {
          color: @menu-item-active-color--dark;
        }
      }

      &.@{prefix}-is-disabled {
        color: @menu-item-disabled-color-dark;
      }

      &:hover:not(.@{prefix}-is-active):not(.@{prefix}-is-opened):not(.@{prefix}-is-disabled) {
        color: @menu-item-hover-color--dark;
        background-color: @menu-item-hover-bg--dark;
      }

      --ripple-color: @menu-item-animation-bg--dark;
    }

    .@{prefix}-menu__popup {
      background: @menu-theme-dark;

      .@{prefix}-menu__item {
        color: @menu-item-color--dark;
        border-radius: @border-radius;

        &.@{prefix}-is-active {
          color: @menu-item-active-color--dark;
          background-color: @menu-item-active-bg--dark;
        }

        &:hover:not(.@{prefix}-is-active) {
          color: @menu-item-hover-color--dark;
          background-color: @menu-item-hover-bg--dark;
        }
      }
    }

    .@{prefix}-head-menu__submenu {
      border-top: 1px solid transparent;
    }

    .@{prefix}-menu__operations {
      &-icon {
        color: @menu-theme-light;

        &:hover {
          background-color: @menu-item-active-bg--dark;
        }
      }
    }

    // menu 双层导航使用了 Tabs 实现，需要 tab 样式保持跟 menu theme 一致，不跟随整体亮色/暗色模式切换
    .@{prefix}-tabs {
      background: @gray-color-11;

      &__nav-item {
        color: #fff;

        &-wrapper {
          --ripple-color: @gray-color-9;
        }

        &:not(.@{prefix}-is-disabled):not(.@{prefix}-is-active):hover {

          .@{prefix}-tabs__nav-item-wrapper {
            background-color: @menu-dark-hover-bg;
          }
        }

        &.@{prefix}-is-active {
          color: @submenu-dark-item-active-color;
        }

        &.@{prefix}-is-disabled {
          color: @menu-item-disabled-color-dark;
        }

        --ripple-color: @gray-color-9;
      }
    }
  }

  &__popup {
    max-height: 0;
    overflow: hidden;
    transition:
      max-height @anim-duration-moderate @anim-time-fn-easing,
      width @anim-duration-moderate @anim-time-fn-easing,
      opacity @anim-duration-base linear;
    position: absolute;
    background: @menu-theme-light;
    z-index: @menu-outer-zindex;
    border-radius: @border-radius;
    opacity: 0;
    .list-style-none();

    &-wrapper {
      padding: 8px;
      height: 100%;
    }

    &.@{prefix}-is-vertical {
      max-height: unset;
      width: 0;

      .@{prefix}-menu__popup-wrapper {
        min-width: 216px;
      }

      &.@{prefix}-is-opened {
        width: var(--popup-width, 216px);
      }
    }

    &.@{prefix}-is-opened {
      max-height: var(--popup-max-height, 364px);
      opacity: 1;
      box-shadow: @menu-default-shadow;
      overflow: visible;

      .@{prefix}-menu__popup {
        top: 0;
        left: calc(100% + @horizontal-spacer);

        &::before {
          content: "";
          display: block;
          position: absolute;
          left: -@horizontal-spacer;
          width: @horizontal-spacer;
          top: 0;
          bottom: 0;
        }
        @horizontal-spacer: 16px;
      }
    }

    .@{prefix}-menu__item {
      color: @menu-popup-item-color;

      + .@{prefix}-menu__item {
        margin-left: 0;
      }

      &.@{prefix}-is-active {
        color: @menu-popup-item-active-color;
        background-color: @menu-popup-item-active-bg;
      }

      &:hover:not(.@{prefix}-is-active) {
        background-color: @menu-popup-item-hover-bg;
      }
    }
  }

  &__operations {
    &-icon {
      margin-right: 16px;
      border-radius: @border-radius;
      color: @menu-item-color--light;
      transition: background-color @anim-duration-moderate @anim-time-fn-easing;

      &:hover {
        background-color: @menu-item-active-bg--light;
      }
    }
  }
}

// opacity-transition
.@{prefix}-opacity-transition {
  transition: opacity @anim-duration-slow cubic-bezier(.55, 0, .1, 1);
}

.horizontal-collapse-transition
.@{prefix}-submenu__title
.@{prefix}-submenu__icon-arrow {
  transition: @anim-duration-base;
  opacity: 0;
}
